﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;

namespace MyCraft
{
    public class FPSCounter
    {
        #region Attributs
        private int _fps; //Nombre de FPS calcules
        private int _nbFrame;//Nombre d'update en cours
        private float _timeElapsed;//Temps ecoule
        #endregion

        #region Constructeur
        public FPSCounter()
        {
            this.Initialize();
        }
        #endregion

        #region Proprietes
        #endregion

        #region Methodes
        public void Initialize()
        {
            _fps = 0;
            _nbFrame = 0;
            _timeElapsed = 0;
        }

        public void LoadContent(ContentManager content)
        {
        }

        public void Update(GameTime gameTime)
        {
            _nbFrame++;
            _timeElapsed += (float)gameTime.ElapsedGameTime.TotalMilliseconds;

            if (_timeElapsed >= 1000)
            {
                _fps = _nbFrame;
                _nbFrame = 0;
                _timeElapsed -= 1000;
            }
            Alert.Alerte("FPS", "fps : " + _fps.ToString(), 100, Color.Red, null);
        }

        public void Draw(SpriteBatch spriteBatch)
        {
        }
        #endregion
    }
}
